home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / math / vhfprp11.zip / VHFPROP.C < prev    next >
C/C++ Source or Header  |  1994-09-26  |  16KB  |  491 lines

  1. /* A computer program to predict VHF propogation */
  2. /* This program has been placed in the Public Domain by its author - K2LMG */
  3. /* Compile under TURBO-C -- The author used BCC Version 2.0 */
  4. /* History:449 */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #include <conio.h>
  10. #include <dos.h>
  11. #include <math.h>
  12.  
  13. #define TRUE        1
  14. #define FALSE        0
  15. #define FADE_VALUE    7
  16. #define VERSION        "1.1"
  17.  
  18. /* 6m data, 0.5 64.3, 1 70.3, 5 118, 10 131, 20 144.5, 30 154, 40 161, 50
  19.         169, 75 174, 100 177.5, 150 183.5, 200 188, 250 194, 300 207, 350 214,
  20.         400 222, 450 229, 500 235, 550 242 */
  21.  
  22. double coef6m[] = {-1.484302997616194e-21, 4.1038152183463572e-18,
  23.         -4.8551992957369198e-15, 3.2101311680399517e-12,
  24.         -1.2996161086602211e-09, 3.3199292557524471e-07,
  25.         -5.3228661204510353e-05, 0.0051731206040884119, -0.28532370451114214,
  26.         8.1911236469791699, 67.635788039642023};
  27.  
  28. /* 2m data -- 0.5 73.9, 1 79.5, 5 93.9 10 131, 20 146, 30 157, 40 167, 50
  29.         170, 75 174, 100 178, 150 184, 200 188.5, 250 194, 300 206.5, 350 214,
  30.         400 222, 450 228, 500 234, 550 241 */
  31.  
  32. double coef2m[] = {-1.0140612223930305e-21, 2.8210504968786972e-18,
  33.         -3.3639226709952115e-15, 2.2467324291152165e-12,
  34.         -9.2161956771287313e-10, 2.3956384975135559e-07,
  35.         -3.9329897909964029e-05, 0.0039527147149096397, -0.22900560651309843,
  36.         7.0593776226319154, 76.297125007618945};
  37.  
  38. /* 1.25m data, 0.5 77.5, 1 83.5, 5 119, 10 132, 20 148, 30 160, 40 168, 50
  39.         171, 75 175.5, 100 180, 150 186.5, 200 191, 250 197, 300 209, 350
  40.         216.5, 400 224, 450 230, 500 236.5, 550 242 */
  41.  
  42. double coef125cm[] = {-9.3022498752972239e-22, 2.5942502213057621e-18,
  43.         -3.1027271861262425e-15, 2.079688661769463e-12,
  44.         -8.5672949008653612e-10, 2.2382801286343053e-07,
  45.         -3.6971168328522354e-05, 0.0037433231319706261, -0.21886313655344825,
  46.         6.8335531497848931, 79.398990370051834};
  47.  
  48. /* 70cm data -- 432 Mhz 0.5 83.4, 1 89.5, 5 103.4 10 132, 20 150, 30 163.5, 40
  49.         170, 50 173, 75 178, 100 183, 150 190, 200 196, 250 202, 300 213, 350
  50.         220.5, 400 228, 450 234, 500 240, 550 246 */
  51.  
  52. double coef70cm[] = {-4.5865358353610324e-22, 1.3108230411727579e-18,
  53.         -1.6135046051301692e-15, 1.1190620728434546e-12,
  54.         -4.8033074993680223e-10, 1.319708437884491e-07,
  55.         -2.3222247971860489e-05, 0.0025516659663546628, -0.1661238781990346,
  56.         5.9666161768039707, 81.595953373755762};
  57.  
  58. /* 33cm data, 0.5 89.7, 1 95.7, 5 119.5, 10 133, 20 153.5, 30 168.5, 40
  59.         173.5, 50 177, 75 183.5, 100 189, 150 197, 200 202.5, 250 209, 300
  60.         221.5, 350 228, 400 236, 450 241.5, 500 248, 550 251 */
  61.  
  62. double coef33cm[] = {-5.2781673891878704e-22, 1.4951138952704982e-18,
  63.         -1.8211439179439397e-15, 1.2472237245268508e-12,
  64.         -5.2709664954563149e-10, 1.4203323864028798e-07,
  65.         -2.4385939877300226e-05, 0.0025983803016192764, -0.16327178023671626,
  66.         5.7118712681798156, 89.957616754542244};
  67.  
  68. /* 23cm data -- 0.5 92.8, 1 98.9, 5 120, 10 134, 20 157, 30 171.5, 40 178,
  69.         50 182, 75 188.5, 100 195, 150 203.5, 200 210, 250 216, 300 228, 350
  70.         234, 400 243, 450 248, 500 254, 550 257 */
  71.  
  72. double coef23cm[] = {-4.324473300406565e-22, 1.2258059596030557e-18,
  73.         -1.4960261442115287e-15, 1.0285157566223974e-12,
  74.         -4.3756476216365891e-10, 1.1917818401558418e-07,
  75.         -2.0805095457433704e-05, 0.002273429714275005, -0.14832922840239154,
  76.         5.4937966328715673, 92.663217031298927};
  77.  
  78. /* Fade data -- Fading data 0.5 0, 5 0, 10 3, 20 5, 30 7, 40 9, 50 11.5, 60
  79.         14.5, 70 16.5, 80 17.5, 90 18, 100 18, 110 17.5, 120 17, 130 16.5, 140
  80.         15.5, 150 14.5, 160 13.5, 170 12.5, 180 11.5, 190 10, 200 9.5, 250 8.5,
  81.         300 8, 350 7.5, 400 7, 450 7, 500 7 */
  82.  
  83. double coeffade[] = {-1.931900179565423e-22, 4.7890688047850891e-19,
  84.         -5.0385411769900302e-16, 2.9177755838734291e-13,
  85.         -1.0055284586681718e-10, 2.0690926814195451e-08,
  86.         -2.3867831104375384e-06, 0.00013095435698746912, -0.003263676118036522,
  87.         0.27959303349242731, -0.376155914778245};
  88.  
  89. double coefheight[] = {1.15144e-08, -3.48166e-06, 4.34947e-04, -2.98883e-02,
  90.     1.20410e+00, -1.84529e+01};
  91.  
  92. double poly_value(double dist, double coeff[], int degree)
  93. { double term;
  94.   int i;
  95.   term = coeff[0];
  96.   for (i = 1; i <= degree; i++)
  97.       term = term * dist + coeff[i];
  98.   return term;
  99. }
  100.  
  101. double path_loss_func(double dist, int freq_index)
  102. { double ret;
  103.   if (dist < 1.0) dist = 1.0;
  104.   switch (freq_index)
  105.     { case 0: ret = poly_value(dist, coef6m, 10);
  106.           break;
  107.       case 1: ret = poly_value(dist, coef2m, 10);
  108.           break;
  109.       case 2: ret = poly_value(dist, coef125cm, 10);
  110.           break;
  111.       case 3: ret = poly_value(dist, coef70cm, 10);
  112.           break;
  113.       case 4: ret = poly_value(dist, coef33cm, 10);
  114.           break;
  115.       case 5: ret = poly_value(dist, coef23cm, 10);
  116.           break;
  117.     }
  118.   return ret;
  119. }
  120.  
  121. double fade_func(double dist)
  122. { if (dist < 0.5 ) dist = 0.5;
  123.   return poly_value(dist, coeffade, 10);
  124. }
  125.  
  126. double height_gain(double height)
  127. { if (height > 100) return 8.0;
  128.   if (height < 0) return -7.0;
  129.   return poly_value(height, coefheight, 5);
  130. }
  131.  
  132. void beep(void)
  133. { printf("%c",7);            /* Beep */
  134. }
  135.  
  136. /* trans array: power, distance, antenna_gain, antenna_height,
  137.     site_height, line_loss, site_angle
  138.  * rec array:   modulation_loss, noise_figure, antenna_gain, antenna_height,
  139.     site_height, line_loss, site_angle, bandwidth, band, dummy;
  140.  */
  141.  
  142. void main()
  143. { char ch, input[20];
  144.   int i, key, row, col, stop, index, mod_index, reliability, band_index,
  145.     fading, key_save;
  146.   double value;
  147.   double transmit[] = {50,10,0,0,0,0,0};
  148.   double receiver[] = {7,1,0,0,0,0,0,5,1,0};
  149.   double distance, hor_dist, dist_lineof_sight, signal2noise, station_gain,
  150.     path_loss, rec_sensitivity, h_gain_trans, h_gain_rec;
  151.   int next_row_left_down[] = {0,0,0,5,5,6,7,8,9,10,13,13,13,5,5,5,5,5,5};
  152.   int next_row_left_up[] = {0,0,0,13,13,13,5,6,7,8,9,10,10,10,13,13,13,13,13,13};    /* this has row 17 defined */
  153.   int next_row_right_down[] = {0,0,0,5,5,6,7,8,9,10,11,15,15,15,15,16,17,18,5};
  154.   int next_row_right_up[] = {0,0,0,18,18,18,5,6,7,8,9,10,11,11,11,11,15,16,17};
  155.   char *mod_mode[] = {"fm","ssb","cw","am"};
  156.   double mod_value[] = {7,3,0,7};
  157.   char *reliab_mode[] = {"50%","99%"};
  158.   char *fade_mode[] = {"No","Yes"};
  159.   char *band[] = {"6m","2m","1.25m","70cm","33cm","23cm"};
  160.   double band_value[] = {50,146,222,440,902,1280};
  161.  
  162.   row = 13;                    /* cursor starting position */
  163.   col = 30;
  164.   band_index = reliability = fading = 1;
  165.   mod_index = 0;
  166.   key_save = 0;
  167.  
  168.   clrscr();
  169.   gotoxy(7,1); printf("VHFProp -- An interactive Signal Analysis Program -- Version %s",VERSION);
  170.   gotoxy(5,3); printf("Transmitting Station Parameters");
  171.   gotoxy(40,3); printf("%c",179);
  172.   gotoxy(45,3); printf("Receiving Station Parameters");
  173.   gotoxy(65,24); printf("Use ESC to Quit");
  174.   gotoxy(1,4);
  175.   for (i=2; i<79; i++)
  176.      printf("%c",196);
  177.   gotoxy(40,4); printf("%c",197);
  178.   for (i=5; i<12; i++)            /* draw vertical bar */
  179.     { gotoxy(40,i);
  180.       printf("%c",179);
  181.     }
  182.   gotoxy(42,14);            /* underline Modes */
  183.   for (i=0; i<34; i++)
  184.      printf("%c",196);
  185.  
  186.   gotoxy(14,18);
  187.   printf("Results");
  188.   gotoxy(2,19);                /* underline Results */
  189.   for (i=0; i<35; i++)
  190.      printf("%c",196);
  191.  
  192.   for(;;)
  193.    { _setcursortype(_NOCURSOR);
  194.      gotoxy(2,5);
  195.      printf("Power (watts):");
  196.      gotoxy(30,5);
  197.      printf("%7.1lf",transmit[0]);
  198.      gotoxy(42,5);
  199.      printf("Noise Figure (db):");
  200.      gotoxy(69,5);
  201.      printf("%7.1lf\n",receiver[1]);
  202.      gotoxy(2,6);
  203.      printf("Line Loss (db):");
  204.      gotoxy(30,6);
  205.      printf("%7.1lf",transmit[5]);
  206.      gotoxy(42,6);
  207.      printf("Line Loss (db): ");
  208.      gotoxy(69,6);
  209.      printf("%7.1lf\n",receiver[5]);
  210.      gotoxy(2,7);
  211.      printf("Antenna Gain (db): ");
  212.      gotoxy(30,7);
  213.      printf("%7.1lf",transmit[2]);
  214.      gotoxy(42,7);
  215.      printf("Antenna Gain (db): ");
  216.      gotoxy(69,7);
  217.      printf("%7.1lf\n",rece